<?php
/**
 * 留言管理模块
 * @author chenhao
 * @copyright 四川呜雷科技有限公司
 * @link http://www.22cn.cn/
 * @since Fri Nov 27 10:13:54 CST 2009
 */

include( "inc/header.php" );
login_check( );
echo "\r\n<body>\r\n";
switch ( $_REQUEST['Action'] )
{
case "verify" :
				$db->query( "UPDATE tun2_book set ".$_GET['Action']."={$_GET['value']} WHERE id={$_GET['id']}" );
				addlog( "修改文档属性", $_SESSION['user_name'] );
				header( "Location:".$_SERVER['HTTP_REFERER'] );
				break;
case "reply" :
				date_default_timezone_set('HongKong');
				$time = time();
				$db->query( "UPDATE tun2_book SET replytime=$time,reply = '".$_POST['reply']."',verify= 1 WHERE id =".$_GET['id']."" );
				addlog( "回复留言", $_SESSION['user_name'] );
				admin_showerr( "<li>回复留言成功</li>", "Admin_Book.php", 1 );
				break;
case "del" :
    $db->query( "DELETE FROM tun2_book WHERE id=".$_GET['id'] );
    addlog( "删除留言", $_SESSION['user_name'] );
    admin_showerr( "<li>留言删除成功</li>", "Admin_Book.php", 1 );
    break;
case "delall" :
    $db->query( "DELETE FROM tun2_book" );
    addlog( "删除全部留言", $_SESSION['user_name'] );
    admin_showerr( "<li>全部留言删除成功</li>", "Admin_Book.php", 1 );
    break;
default :
    $execc = "select count(*) from tun2_book";
    $resultc = mysql_query( $execc );
    $rsc = mysql_fetch_array( $resultc );
    @$intNum = $rsc[0];
    @$intPerpage = 10;
    if ( $_GET['PB_page'] )
    {
        $offset = ( $_GET['PB_page'] - 1 ) * $intPerpage;
    }
    else
    {
        $offset = 0;
    }
    $db->query( "SELECT * FROM tun2_book Order by ID desc limit ".$offset.",{$intPerpage}" );
    echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n\r\n  <tr>\r\n    <td width=\"4%\" align=\"center\"><strong>ID</strong></td>\r\n     <td align=\"center\"><strong>留言内容</strong></td>\r\n  <td align=\"center\"><strong>审核</strong></td>\r\n   <td width=\"20%\" align=\"center\"><strong>留言时间</strong></td>\r\n    <td width=\"8%\" align=\"center\"><strong>操作</strong></td>\r\n  </tr>\r\n";
    while ( $db->next_record( ) )
    {
        echo "  <tr>\r\n    <td align=\"center\">";
        echo $db->Record['id'];
        echo "</td>\r\n    <td>";
		echo "<font color=#EA0000><strong>";
		echo $db->Record['name'];
		echo "</strong></font>(<font color=#9D9D9D>IP：";
		echo $db->Record['ip'];
		echo "       联系方式：";
		echo $db->Record['contact'];
		if (!empty($db->Record['companyname'])) {
			echo "       公司名称：";
			echo $db->Record['companyname'];
		}
		echo "</font>)留言主题：";
		echo $db->Record['title'];
		echo "<br \><br \>留言内容：<br \>";
        echo $db->Record['content'];
        echo "<br/><br/><font color=#EA0000>回复：</font><br/><form action=\"Admin_Book.php?Action=reply&id=".$db->Record['id']."\" method=\"post\"name=\"reply\"> <textarea rows=\"5\" cols=\"60\" name=\"reply\">";
		echo $db->Record['reply'];
		echo "</textarea><br/><input   type=\"submit\" value=\"提交\"name=\"replysubmit\" /></form></td>\r\n <td align=\"center\"> <form action=\"Admin_Book.php\" method=\"post\" name=\"form\">  ";
        if ( $db->Record['verify'] == 0 )
								{
												echo "<a href=\"Admin_Book.php?Action=verify&id=".$db->Record['id']."&value=1\"><img src=\"images/icon_02.gif\" border=\"0\" /></a>";
								}
								else
								{
												echo "<a href=\"Admin_Book.php?Action=verify&id=".$db->Record['id']."&value=0\"><img src=\"images/icon_01.gif\" border=\"0\" /></a>";
								}
		echo "</form></td>\r\n   <td align=\"center\">";
        echo $db->Record['time'];
        echo "</td>\r\n    <td align=\"center\"><a href=\"Admin_Book.php?Action=del&id=";
        echo $db->Record['id'];
        echo "\">删除</a></td>\r\n  </tr>\r\n\r\n";
    }
    echo "</form>\r\n<form action=\"Admin_Book.php?Action=delall\" method=\"post\">\r\n  <tr>\r\n    <td colspan=\"5\" align=\"center\">\r\n    <input type=\"submit\" name=\"Submit_delall\" value=\"删除全部留言\"/></td>\r\n  </tr>\r\n</form>\r\n</table>\r\n";
    require_once( "../inc/class.page.php" );
    class mypage extends page
    {

        public function show( )
        {
            $showpage = "<div class=\"pagenavi\" id=\"lopage\">";
            $showpage .= $this->first_page( )." ";
            $showpage .= $this->nowbar( "", "curr" );
            $showpage .= "<span class=\"break\">...</span>";
            $showpage .= $this->last_page( );
            $showpage .= "   (总计<span class=\"num\">".$this->totalpage."</span>页 <span class=\"num\">".$this->total."</span>条记录)</div>";
            $showpage .= "</div>";
            return $showpage;
        }

    }

    $page = new mypage( array(
        "total" => $intNum,
        "perpage" => $intPerpage
    ) );
    echo $page->show( );
}
echo "</body>\r\n</html>\r\n";
?>
